﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data.SqlClient;


namespace Electure.DAL
{
    public class Category: BaseModel
    {
        public string Name { get; set; }
        public DateTime CreateDate { get; set; }
        public DateTime EditDate { get; set; }
        public string Description { get; set; }        
    }

    public class CategoryRepository : BaseRepository<Category>
    {
        internal CategoryRepository() { }
        protected override int create(Category instance)
        {
            return connection.Execute("INSERT INTO category(Name,Description) VALUES (@Name, @Description)", instance);
        }
        public override bool Update(Category instance)
        {
            return connection.Execute("UPDATE category SET name=@Name, description=@Description, editdate = getutcdate() WHERE id = @ID", instance) == 1;
        }
        public override bool Delete(int id)
        {
            return connection.Execute("DELETE FROM category WHERE ID = @id", new {id = id}) == 1;
        }
        public override List<Category> GetAll()
        {
            return connection.Query<Category>("SELECT * FROM category").ToList();
        }
    }
}
